package cn.yunhe.crm.service;


import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.yunhe.crm.dao.OrganizationMapper;
import cn.yunhe.crm.entity.Organization;
@Service("OrganizationService")
public class OrganizationService {
	@Autowired
	private OrganizationMapper oMapper;
	
	public void setoMapper(OrganizationMapper oMapper) {
		this.oMapper = oMapper;
	}
	/**
	 * 查询机构总数
	 * @return
	 */
	public int checkCount(){
		return oMapper.countByExample(null);
	}
	/**
	 * 根据时间查询机构总数
	 * @param begintime
	 * @param endtime
	 * @return
	 */
	public int checkCountByYearAndMonth(String begintime,String endtime){
		Map map=new HashMap();
		map.put("begintime", begintime);
		map.put("endtime", endtime);
		return oMapper.checkCountByYearAndMonth(map);
	}
	
	
	/**
	 * 查询所有机构信息列表
	 * @return
	 */
	public List<Organization> findAllOrganization(){
		return oMapper.findAllOrganization();
	}
	

	/**

	 * 根据id获取机构信息,包括联系人和经办人

	 * @param oid

	 * @return

	 */
	public Organization getOrgById(Integer oid) {
		// TODO Auto-generated method stub

		return oMapper.findOrganizationById(oid);
	}
	
	/**
	 * 根据id改变机构的状态，实现删除
	 * @param id
	 * @return
	 */
	public int editOrganStateById(Integer id){
		int flag=oMapper.editOrganStateById(id);
		if(flag>0){
			return 1;
		}else{
			return 0;
		}
	}
	/**
	 * 验证机构名称
	 * @param organization
	 * @return
	 */
	public Organization researchOrganziation(String organame){
		return oMapper.researchOrganziation(organame);
		
	}
	/**
	 * 添加机构
	 * @param record
	 * @return
	 */
	public int insertOrganization(Organization organization){
		int flag=oMapper.insertOrganization(organization);
		if(flag>0){
			return 1;
		}else{
			return 0;
		}
	}
	
	public int updateOrganById(Organization organization){
		int flag=oMapper.updateOrganById(organization);
		if(flag>0){
			return 1;
		}else {
			return 0;
		}
	}
	
	/**
	 * 获取所有的机构信息，包含联系人，经办人（日志管理部分）
	 * @return
	 */
	public List<Organization> getOrgList() {
		// TODO Auto-generated method stub
		return oMapper.findOrganizationForAjax();
	}
	
	public int countByToday(){
		return oMapper.checkCountByToday();
	}
	
}
